<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>后台首页</title>
</head>
<body>
<form action="/manage/" method="get">
    博客标题: <input type="text" name="article_title" value="{{ article_title }}"><br>
    发表时间: <input type="text" name="start_time" value="{{ start_time }}">
    - <input type="text" name="end_time" value="{{ end_time }}"><br>
    博客类别: <select name="article_category_id">
    <option value="0">--请选择--</option>
    {% for category in article_category %}
        <option value="{{ category.id }}"
                {% if article_category_id == category.id|stringformat:'s' %}
                selected {% endif %}>{{ category.category_name }}</option>
    {% endfor %}
</select> <br>
    <input type="submit" value="提交">
</form>
<button><a href="/manage/add/">添加文章</a></button>
<button><a href="/manage/category/">类别管理</a></button>
<form action="/manage/del/batch/" method="get">
    <input type="submit" value="批量删除"/>
    <table border="1">
        <thead>
        <tr>
            <th><input type="checkbox" name="all" id="all"></th>
            <th>编号</th>
            <th>标题</th>
            <th>类别</th>
            <th>添加时间</th>
            <th>修改时间</th>
            <th>查看次数</th>
            <th>评论次数</th>
            <th>查看评论</th>
            <th>操作</th>
        </tr>
        </thead>
        <tbody>
{#        {% for article in articles %}#}
        {% for article in current_page %}
            <tr>
                <td>
                    <input type="checkbox" name="ids" value="{{ article.id }}"/>
                </td>
                <td>{{ article.id }}</td>
                <td>{{ article.article_title }}</td>
                <td>{{ article.category.category_name }}</td>
                <td>{{ article.create_time|date:'Y-m-d' }}</td>
                <td>{{ article.update_time|date:'Y-m-d' }}</td>
                <td>{{ article.article_views }}</td>
                <td>{{ article.comment }}</td>
                <td>
                    <a href="/manage/comments/{{ article.id }}">查看评论</a>
                </td>
                <td>
                    <a href="/manage/update/{{ article.id }}">修改</a> <br>
                    <a href="/manage/del/{{ article.id }}">删除</a>
                </td>
            </tr>
        {% empty %}
            <div>暂无数据</div>
        {% endfor %}
        </tbody>
    </table>
</form>
<div>
    {% if current_page.has_previous %}
        <a href="/manage?page_index={{ current_page.previous_page_number }}&article_title={{ article_title }}&article_category_id={{ article_category_id }}&start_time={{ start_time }}&end_time={{ end_time }}">上一页</a>
    {% endif %}
    {# 使用page_range方法遍历 #}
    {% for page_index in paginator.page_range %}
        <a href="/manage?page_index={{ page_index }}&article_title={{ article_title }}&article_category_id={{ article_category_id }}&start_time={{ start_time }}&end_time={{ end_time }}">{{ page_index }}</a>
    {% endfor %}
    {% if current_page.has_next %}
        <a href="/manage?page_index={{ current_page.next_page_number }}&article_title={{ article_title }}&article_category_id={{ article_category_id }}&start_time={{ start_time }}&end_time={{ end_time }}">下一页</a>
    {% endif %}
    {# 使用count获取总条数 #}
    共有：{{ paginator.count }}
</div>
</body>
</html>